package com.daodao.daodaoschedule.infrastructure.repository.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.daodao.daodaoschedule.domain.wechat.RemindEvent;
import com.daodao.daodaoschedule.infrastructure.dao.entity.RemindEventPO;
import com.daodao.daodaoschedule.infrastructure.dao.mapper.RemindEventMapper;
import com.daodao.daodaoschedule.infrastructure.repository.RemindEventRepository;
import com.daodao.daodaoschedule.infrastructure.util.BeanCopyUtils;
import lombok.AllArgsConstructor;
import org.apache.tomcat.jni.Local;
import org.springframework.stereotype.Repository;

import java.time.LocalDate;
import java.util.List;

/**
 * @author mal
 * @date 2023-02-15 16:06
 */
@Repository
@AllArgsConstructor
public class RemindEventRepositoryImpl implements RemindEventRepository {

    private final RemindEventMapper remindEventMapper;

    @Override
    public List<RemindEvent> getValidEventList() {
        List<RemindEventPO> eventPOList = remindEventMapper.selectList(
                new LambdaQueryWrapper<RemindEventPO>()
                        .le(RemindEventPO::getStartDate, LocalDate.now())
                        .ge(RemindEventPO::getEndDate, LocalDate.now())
        );


        return BeanCopyUtils.mapAsList(eventPOList, RemindEvent.class);
    }
}
